package com.shqcjd.sinopecdemomobile.ui.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shqcjd.sinopecdemomobile.R;
import com.shqcjd.sinopecdemomobile.util.UIUtils;

import java.util.List;

public class PlaybackItemAdapter extends BaseQuickAdapter<String,BaseViewHolder> {
    private Context context;
    private List<String> data;
    public PlaybackItemAdapter(@Nullable List<String> data, Context context) {
        super(R.layout.item_playback_item, data);
        this.context = context;
        this.data = data;
    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {
        ImageView iv_item_playback = helper.getView(R.id.iv_item_playback);
        if(data.size()>9&&helper.getAdapterPosition()==8){
                helper.getView(R.id.tv_item_playback_cover).setVisibility(View.VISIBLE);
        }else{
            helper.getView(R.id.tv_item_playback_cover).setVisibility(View.INVISIBLE);
        }
        if(UIUtils.getFormatName(item).equals(".mp4")){
            if(data.size()>9&&helper.getAdapterPosition()==8){
                helper.getView(R.id.iv_item_playback_video).setVisibility(View.INVISIBLE);
            }else{
                helper.getView(R.id.iv_item_playback_video).setVisibility(View.VISIBLE);
            }
            RequestOptions options = new RequestOptions()
                    .placeholder(R.mipmap.ic_default_small)	//加载成功之前占位图
                    .error(R.mipmap.ic_default_small);//指定图片的缩放类型为centerCrop （等比例缩放图片，直到图片的宽高都
            Glide.with(context)
                    .load(item)
                    .apply(options)
                    .thumbnail( 0.1f )
                    .into(iv_item_playback);
        }else{
            helper.getView(R.id.iv_item_playback_video).setVisibility(View.INVISIBLE);
            RequestOptions options = new RequestOptions()
                    .placeholder(R.mipmap.ic_default_small)	//加载成功之前占位图
                    .error(R.mipmap.ic_default_small);//指定图片的缩放类型为centerCrop （等比例缩放图片，直到图片的宽高都
            Glide.with(context)
                    .load(item)
                    .apply(options)
                    .into(iv_item_playback);
        }

    }

    @Override
    public int getItemCount() {
        return data.size()>9?9:data.size();
    }
}
